package com.tancire.web.controller.market;

import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.core.page.TableDataInfo;
import com.tancire.net.domain.ShopTask;
import com.tancire.net.service.IShopTaskService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 任务管理Controller
 *
 * @author chenchao
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/mkt/shop/task")
public class ShopTaskMktController extends BaseController {
    @Resource
    private IShopTaskService shopTaskService;

    /**
     * 查询任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('company:user:union')")
    @GetMapping("/list")
    public TableDataInfo list(ShopTask shopTask) {
        // 仅查询已上架的
        shopTask.setTaskStatus("1");
        startPage();
        List<ShopTask> list = shopTaskService.selectShopTaskList(shopTask);
        return getDataTable(list);
    }

    /**
     * 获取任务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('net:shopTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(shopTaskService.selectShopTaskById(id));
    }

    /**
     * 推广资源
     */
    @PreAuthorize("@ss.hasPermi('company:user:union')")
    @GetMapping(value = "/promotion/{id}")
    public AjaxResult promotion(@PathVariable("id") Long id) {
        shopTaskService.promotionShopTask(id);
        return AjaxResult.success();
    }

}
